package lang

import (
	"strconv"

	"gitee.com/ktark/ktark-framework/ktark-core/util/number"
)

// ==================
// lang-lang: lang
// ==================

type Int interface {
	Value() int
	IntValue()
	LongValue() int64
	Long() Long
}

type Double interface {
	Value() float64
	IntValue() int
	Int32Value() int32
	Int64Value() int64
	DoubleValue()
	LongValue() int64
	Long() Long
	Int() Int
	Doubles() Doubles
}

type Short interface {
	IntValue() int
	Value() int16
	// ShortValue 标识接口
	ShortValue()
	Shorts() Shorts
}

type Boolean interface {
	Value() bool
}

// Byte byte
type Byte struct {
	value byte
}

// Shorts of int16
type Shorts struct {
	value int16
}

// uShort unit16
type uShort struct {
	value uint16
}

// Integer int
type Integer struct {
	value int
}

// uInteger uint
type uInteger struct {
	value uint
}

// Long int64
type Long struct {
	value int64
}

// uLong uint64
type uLong struct {
	value uint64
}

// Float float32
type Float struct {
	value float32
}

// Doubles float64
type Doubles struct {
	value float64
}

// Char Char
type Char struct {
	value rune
}

// String string
type String struct {
	value string
}

// Booleans bool
type Booleans struct {
	value bool
}

func (i *Integer) ToString() string {
	return strconv.Itoa(i.value)
}

func (i *Integer) Long() Long {
	return Long{int64(i.value)}
}

func (i *Integer) LongValue() int64 {
	return int64(i.value)
}

func (i *Integer) IntValue() {

}
func (i *Integer) Value() int {
	return i.value
}

func (d *Doubles) Long() Long {
	return Long{int64(d.value)}
}

func (d *Doubles) LongValue() int64 {
	return int64(d.value)
}

func (d *Doubles) IntValue() int {
	return int(d.value)
}

func (d *Doubles) Int64Value() int64 {
	return int64(d.value)
}

func (d *Doubles) Int32Value() int32 {
	return int32(d.value)
}

func (d *Doubles) DoubleValue() {
}

func (d *Doubles) Doubles() Doubles {
	return *d
}

func (d *Doubles) Int() Int {
	return &Integer{value: int(d.value)}
}

func (d *Doubles) Value() float64 {
	return d.value
}

func (s *Shorts) IntValue() int {
	return int(s.value)
}

func (s *Shorts) Value() int16 {
	return s.value
}

func (s *Shorts) ShortValue() {
}

func (s *Shorts) Shorts() Shorts {
	return *s
}

func (b *Booleans) Value() bool {
	return b.value
}

func (b *Booleans) SetValue(val bool) {
	b.value = val
}

// ParerShort 解析为short
func ParerShort(s string) Short {
	num, err := number.ParseInt16(s)
	if err != nil {
		return nil
	} else {
		return &Shorts{value: num}
	}
}

// ParerDouble 解析为 double
func ParerDouble(s string) Double {
	num, err := number.ParseFloat64(s)
	if err != nil {
		return nil
	} else {
		return &Doubles{value: num}
	}
}

// ParerInt 解析为 int
func ParerInt(s string) Int {
	num, err := number.ParseInt(s)
	if err != nil {
		return nil
	} else {
		return &Integer{value: num}
	}
}
